﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebClient.admin.Modules.diaryProducts
{
    public partial class Edit : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.btnAddNew.Attributes.Add("onclick", "return OnSubmitClick();");
            if (!this.IsPostBack)
            {
                loadCbb();
                InitItem();
            }
        }

        void loadCbb() { 
            WebData db = new WebData();
            this.cbbproductId.DataSource = db.GetAllProducts();
            this.cbbproductId.DataTextField = DTO.Products.c_productName;
            this.cbbproductId.DataValueField = "id";
            this.cbbproductId.DataBind();

        }

        private void AddNew(){
		    WebData data = new WebData();
		    DTO.Diaryproducts item  = new DTO.Diaryproducts();		
		    item.price =Convert.ToDecimal(this.cbbproductId.SelectedValue);
            item.lastUpdate = DateTime.Now;
            item.isActive = 1;
            data.OnSubmitDiaryproducts(item, 0);
	    }

        private void InitItem(){
		    ViewState["URLReferrer"] = Request.UrlReferrer.AbsoluteUri;
		    WebData db=new WebData();
		    DTO.Diaryproducts item  = new DTO.Diaryproducts();
		    if (item != null){
                cbbproductId.SelectedValue = item.productId.ToString();
			     txtprice.Text = item.price.ToString();			 
		    }
	
	    }
        protected void btnAddNew_Click(object sender, EventArgs e)
        {
            AddNew();
        }
    }
}